package servlet;

import core.ServletBase;
import weka.AssociationsHelpper;
import weka.CommonUtils;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by taohj on 2014/12/26.
 */
@WebServlet("/associationsServlet")
public class AssociationsServlet extends ServletBase {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        String action=req.getParameter("action");
        if ("start".equals(action)){
            try {
          startAssociator(req,resp);
            } catch (Exception e) {
                e.printStackTrace();
               super.print(resp,e.getLocalizedMessage());
            }
        }else if("input".equals(action)){
            req.getRequestDispatcher("WEB-INF/page/tabs/associate/associate.jsp").forward(req, resp);
        }




    }




    public  void  startAssociator(HttpServletRequest request,HttpServletResponse response) throws Exception {


       String associatorClass=request.getParameter("associator");
        String options=request.getParameter("option");
        String result = new AssociationsHelpper(getCurrentFilePath(request),associatorClass,options).start().toString();
        result = result.replaceAll(" ", "\u007F ");
        print(response,result);



    }
}
